package DatingApp;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.AutoTextEditField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.PasswordEditField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;

import net.rim.device.api.ui.component.BitmapField;

/**
 * A class extending the MainScreen class, which provides default standard
 * behaviour for BlackBerry GUI applications.
 */
public final class DatingScreen extends MainScreen implements FieldChangeListener
{
	private AutoTextEditField userField;/*, passField;*/                   //define the edit fields
	private PasswordEditField passField;
    private ButtonField showInputButton, registerButton; 
    /**
     * Creates a new DatingScreen object
     */
    public DatingScreen()
    {        
    	new VerticalFieldManager();
    	
    	// TODO BBM pin for login
        userField = new AutoTextEditField("Username: ","Bobby Jones");  //define edit fields
        passField = new PasswordEditField("Password: ","what");
        showInputButton = new ButtonField("SUBMIT");     //define button titles
        showInputButton.setChangeListener(this);
        new BitmapField(Bitmap.getBitmapResource("logo_small.png"));
        
        registerButton = new ButtonField("REGISTER");
        registerButton.setChangeListener(this);
        
        this.createLayout();
    }
    
    /**
     * Sets the layout of the main application screen.
     */
    public void createLayout(){
    	Manager temp = new HorizontalFieldManager(HorizontalFieldManager.FIELD_HCENTER);
    	setTitle("BlackBerry Dating Application");
    	
    	add(userField);
        add(passField);
        temp.add(showInputButton);
        temp.add(registerButton);
        add(temp);
    }
    

    /**
     * This method listens for button events.
     * 
     * @param	field	Button that fired an event.
     * @param	context	(I have no idea how this works)
     */
    public void fieldChanged(Field field, int context){
        if (field == showInputButton){
            //Dialog.alert("Logging in."); //show text from first input field
        	UiApplication.getUiApplication().pushScreen(new ControlPanel());
        }else if (field == registerButton){
        	UiApplication.getUiApplication().pushScreen(new Registration());
        }
       
    }
    
    /**
     * Exits main application and displays user notification.
     */
    public boolean onClose() //fires if application is closed
    {
        Dialog.alert("Exiting.");
        System.exit(0);
            return true;
    }
    
}
